// test_instance_manager.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "skype_event_dispatcher.h"
#include <iostream>
#include <memory>
#include <atlbase.h>
#include <atlcom.h>

#import "Skype4COM.dll" named_guids


namespace TestSkypeProxy
{
	class NullAttachEventHandler 
		: public SkypeProtection::AttachEventHandler
	{
	public:
		virtual void OnAttaching()
		{
		}
	};

	class NullSkypeEventHandler
		: public SkypeProtection::SkypeEventHandler
	{
	public:
		virtual void OnCommand(SKYPE4COMLib::ICommand* pCommand)
		{
		}
		virtual void OnReply(SKYPE4COMLib::ICommand* pCommand)
		{
		}
		virtual void OnError(SKYPE4COMLib::ICommand* pCommand, LONG Number, BSTR Description)
		{
		}
		virtual void OnAttachmentStatus(SKYPE4COMLib::TAttachmentStatus Status)
		{
		}
		virtual void OnConnectionStatus(SKYPE4COMLib::TConnectionStatus Status)
		{
		}
		virtual void OnUserStatus(SKYPE4COMLib::TUserStatus Status)
		{
		}
		virtual void OnOnlineStatus(SKYPE4COMLib::IUser* pUser, SKYPE4COMLib::TOnlineStatus Status)
		{
		}
		virtual void OnCallStatus(SKYPE4COMLib::ICall* pCall, SKYPE4COMLib::TCallStatus Status)
		{
		}
		virtual void OnCallHistory()
		{
		}
		virtual void OnMute(VARIANT_BOOL Status)
		{
		}
		virtual void OnMessageStatus(SKYPE4COMLib::IChatMessage* pMessage, SKYPE4COMLib::TChatMessageStatus Status)
		{
			std::cout << "new message: " << (char*)pMessage->GetBody() << std::endl;
		}
		virtual void OnMessageHistory(BSTR Username)
		{
		}
	};
}


int _tmain(int argc, _TCHAR* argv[])
{
	using namespace SkypeProtection;
	using namespace TestSkypeProxy;
	using namespace SKYPE4COMLib;

	std::auto_ptr<AttachEventHandler> attachHandler1(new NullAttachEventHandler());
	std::auto_ptr<SkypeEventHandler> skypeHandler1(new NullSkypeEventHandler());

	std::auto_ptr<AttachEventHandler> attachHandler2(new NullAttachEventHandler());
	std::auto_ptr<SkypeEventHandler> skypeHandler2(new NullSkypeEventHandler());

	SkypeEventDispatcherParams params;
	params.AttachHandler = attachHandler1.release();
	params.SkypeHandler = skypeHandler1.release();
	params.dispatch_events = true;
	std::auto_ptr<SkypeEventDispatcher> dispatcher = CreateSkypeEventDispatcher(params);
	if (!dispatcher.get())
		std::cout << "proxy1 is null" << std::endl;
	

	params.AttachHandler = attachHandler2.release();
	params.SkypeHandler = skypeHandler2.release();
	params.dispatch_events = true;
	std::auto_ptr<SkypeEventDispatcher> dispatcher2 = CreateSkypeEventDispatcher(params);
	if (!dispatcher2.get())
		std::cout << "proxy2 is null" << std::endl;

	Sleep(40000);

	/*ISkypePtr skype = proxy->GetSkypeInstance();

	// Chats
	SKYPE4COMLib::IChatCollectionPtr ChatCollection = skype->GetChats();
	long Count = ChatCollection->GetCount();
	std::cout << "Chats count -" << Count << std::endl;

	for (long i = 1; i <= Count; ++i)
	{
		_bstr_t Name = ChatCollection->GetItem(i)->GetName();
		std::cout << "Name: " << (LPCSTR)Name << std::endl;
	}

	SKYPE4COMLib::IChatPtr Chat = ChatCollection->GetItem(1);
	std::string str("Hello world");
	_bstr_t text(str.c_str());
	Chat->SendMessage(text);

	ChatCollection = NULL;*/
			
	return 0;
}

